package com.course.business.controller.admin;

import com.course.server.dto.MemberCourseDto;
import com.course.server.dto.PageDto;
import com.course.server.dto.ResponseDto;
import com.course.server.service.MemberCourseService;
import com.course.server.util.ValidatorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/memberCourse")
public class MemberCourseController {

private static final Logger LOG = LoggerFactory.getLogger(MemberCourseController.class);
public static final String BUSINESS_NAME = "会员课程报名";

@Resource
private MemberCourseService memberCourseService;

/**
* 列表查询
*/
@PostMapping("/list")
public ResponseDto memberCourse(@RequestBody PageDto pageDto) {
ResponseDto responseDto = new ResponseDto();
memberCourseService.list(pageDto);
responseDto.setContent(pageDto);
return responseDto;
}


/**
* 保存，id有值时更新，无值时新增
*/
@PostMapping("/save")
public ResponseDto save(@RequestBody MemberCourseDto memberCourseDto) {
// 保存校验
            ValidatorUtil.require(memberCourseDto.getMemberId(), "会员id");
            ValidatorUtil.require(memberCourseDto.getCourseId(), "课程id");
            ValidatorUtil.require(memberCourseDto.getAt(), "报名时间");

ResponseDto responseDto = new ResponseDto();
memberCourseService.save(memberCourseDto);
responseDto.setContent(memberCourseDto);
return responseDto;
}

/**
* 删除
*/
@DeleteMapping("/delete/{id}")
public ResponseDto save(@PathVariable String id) {
ResponseDto responseDto = new ResponseDto();
memberCourseService.delete(id);
return responseDto;
}
}